import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { SeriesPage } from './series/series'
import { PhotoLibrary } from '@ionic-native/photo-library';
import { StatusBar } from '@ionic-native/status-bar';


@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {
  private series = [{'bg':'url("assets/pic/mtl_1_m.png")','title':'Romantic'},
                    {'bg':'url("assets/pic/hyy_1_m.png")','title':'Flowers'},
                    {'bg':'url("assets/pic/cy_1_m.png")','title':'Buddhist'},
                    {'bg':'url("assets/pic/dw_1_m.png")','title':'Zoology'},
                    {'bg':'url("assets/pic/sl_1_m.png")','title':'Tree'},
                    {'bg':'url("assets/pic/jz_1_m.png")','title':'Erection'},]
  constructor(public navCtrl: NavController,
    private photoLibrary: PhotoLibrary,
    private statusBar: StatusBar) {
      this.getPicturesFromLocal();
      this.statusBar.overlaysWebView(true);
      // this.statusBar.backgroundColorByHexString('gradient(linear, 0 0, right 0, from(#5764de), to(rgba(147, 67, 228, 0.5)))')
  }

  openSeries(title: string) :void{
    switch(title){
      case 'Romantic': title = 'mtl';break;
      case 'Flowers': title = 'hyy';break;
      case 'Buddhist': title = 'cy';break;
      case 'Zoology': title = 'dongwu';break;
      case 'Tree': title = 'sl';break;
      case 'Erection': title = 'jz';break;
    }
    this.navCtrl.push(SeriesPage,{title:title});
  }

  
  getPicturesFromLocal(){
    this.photoLibrary.requestAuthorization().then(() => {
      this.photoLibrary.getLibrary({includeAlbumData: true}).subscribe({
        error: err => { console.log('could not get photos'); },
        complete: () => { console.log('done getting photos'); }
      });
    })
    .catch(err => console.log('permissions weren\'t granted'));
  }
}
